package rainQuality.rain;

import rainQuality.entity.RainManage;
import rainQuality.servlet.RainManageService;
import rainQuality.servlet.impl.RainManageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/Xz")
public class XzServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求编码格式
        request.setCharacterEncoding("utf-8");
        //设置响应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        String date=request.getParameter("date");
        String yu=request.getParameter("yu");
        String stati=request.getParameter("stat");
        String add=request.getParameter("add");

        PrintWriter out=response.getWriter();

        RainManage rainManage=new RainManage(name,date,yu,stati,add);
        RainManageService rainManageService=new RainManageServiceImpl();
        int count=rainManageService.Xz(rainManage);
        if(count>0){
            out.print("<script type=\"text/javascript\">\n" +
                    "    alert(\"新增成功\");\n" +
                    "    location.href=\"http://localhost:8080/untitled1_war_exploded/RainManag/cx.jsp\";\n" +
                    "</script>");
        }else{
            out.print("<script type=\"text/javascript\">\n" +
                    "    alert(\"新增失败\");\n" +
                    "    location.href=\"http://localhost:8080/untitled1_war_exploded/RainManag/cx.jsp\";\n" +
                    "</script>");
        }
        out.flush();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
